package com.example.advice;

/**全局异常处理
 * @author wuyuhong
 * @date 2021/06/08 22:22
 **/

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class MyGlobalData {
        @ModelAttribute("info")  //这个注解说明是全局变量,指定名字未info
    public Map<String,String> mydata(){
        Map<String, String> map = new HashMap();
        map.put("name","三毛");
        map.put("age","18");
        return map;
    }
    @InitBinder("b")
    public void b(WebDataBinder binder){
            binder.setFieldDefaultPrefix("b.");
    }
    @InitBinder("a")
    public void a(WebDataBinder binder){
        binder.setFieldDefaultPrefix("a.");
    }

}
